package Thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author lyx
 * @Date 2021/6/25 10:22
 */
public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        myThread mythread = new myThread();
        //适配类
        FutureTask futureTask =new FutureTask(mythread);
        FutureTask futureTask1 =new FutureTask(mythread);
        //启动Callable
        new Thread(futureTask,"A").start();
        new Thread(futureTask1,"B").start();//结果缓存
        new Thread(futureTask,"C").start();//结果缓存

        System.out.println("输出Callable返回值:"+futureTask.get().toString());

    }

}


class myThread implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("线程名字:"+Thread.currentThread().getName());
        System.out.println("打印内容:call()");
        return 1024;
    }
}